
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:core_foundation/permission/page_permission.dart';

class PagePermissionTest extends StatefulWidget {
  static const rName = "page_permission_test";
  @override
  _PagePermissionTestState createState() => _PagePermissionTestState();
}

class _PagePermissionTestState extends State<PagePermissionTest> {
  @override
  Widget build(BuildContext context) {
    return _();
  }

  _() {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
        actions: <Widget>[
          IconButton(
            icon: const Icon(Icons.settings),
            onPressed: () async {
              var hasOpened = openAppSettings();
              debugPrint('App Settings opened: ' + hasOpened.toString());
            },
          )
        ],
      ),
      body: Center(
        child: ListView(
            children: Permission.values
                .where((Permission permission) {
              if (Platform.isIOS) {
                return permission != Permission.unknown &&
                    permission != Permission.sms &&
                    permission != Permission.storage &&
                    permission != Permission.ignoreBatteryOptimizations &&
                    permission != Permission.accessMediaLocation;
              } else {
                return permission != Permission.unknown &&
                    permission != Permission.mediaLibrary &&
                    permission != Permission.photos &&
                    permission != Permission.reminders;
              }
            })
                .map((permission) => PagePermission(permission))
                .toList()),
      ),
    );
  }
}
